package com.jhy.study2.entity;

import org.jetbrains.annotations.NotNull;

public class Dog implements Comparable<Dog> {
    private String dogName;
    private int dogAge;

    public Dog(){}
    public Dog(String dogName,int dogAge){
        this.dogAge = dogAge;
        this.dogName = dogName;
    }


    public String getDogName() {
        return dogName;
    }

    public void setDogName(String dogName) {
        this.dogName = dogName;
    }

    public int getDogAge() {
        return dogAge;
    }

    public void setDogAge(int dogAge) {
        this.dogAge = dogAge;
    }

    @Override
    public int compareTo(@NotNull Dog o) {
        if(this.dogName.compareTo(((Dog)o).getDogName()) == 0){  //如果狗名一样，我们比较年龄
            return this.dogAge - ((Dog)o).getDogAge();
        }
        return this.dogName.compareTo(((Dog)o).getDogName());
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Dog{");
        sb.append("dogName='").append(dogName).append('\'');
        sb.append(", dogAge=").append(dogAge);
        sb.append('}');
        return sb.toString();
    }
}
